<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/12 0012
 * Time: 下午 17:05
 */

namespace frontend\models;


use common\models\c2\entity\ActivityPlayerModel;
use common\models\c2\statics\ActivityPlayerState;
use yii\helpers\ArrayHelper;

class ActivityApplyForm extends ActivityPlayerModel
{

    public function rules()
    {
        return ArrayHelper::merge(parent::rules(), [
            [['content', 'title', 'activity_id'], 'required'],
        ]);
    }

    public function afterSave($insert, $changedAttributes)
    {
        parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
        if ($insert) {
            $activityModel = $this->activity;
            if ($activityModel->is_check == 1) {
                $this->updateAttributes(['state' => ActivityPlayerState::STATE_NOT_CHECK]);
            } elseif ($activityModel->is_check == 0) {
                $this->updateAttributes(['state' => ActivityPlayerState::STATE_CHECKED]);
            }
        }
    }

}